package main;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import domain.entities.EntitiesEnum;
import domain.layer.IDataLayer;
import framework.exceptions.EntityClassNotFoundException;
import framework.logging.ISpringLogger;

public class MainClass{


  public static void main(String[] args) {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml");
    
    IDataLayer dataLayerBean = (IDataLayer) ctx.getBean("DataLayerBean");
    ISpringLogger loggerBean = (ISpringLogger) ctx.getBean("LoggerBean");    
    
    try {
      dataLayerBean.getEntityList(EntitiesEnum.ESUB);
      dataLayerBean.getEntityList(EntitiesEnum.EVERB);
      dataLayerBean.getEntityList(EntitiesEnum.EWORD);
    } catch (EntityClassNotFoundException e) {
      e.printStackTrace();
    }
    
//    dataLayerBean.addEntity(null);
//    dataLayerBean.getEntityList(EntitiesEnum.ESUB);
    //List verbs = beanLayer.getVerbs();
//    for ( Iterator iter = subs.iterator(); iter.hasNext(); ){
//      ESub loadedMsg = (ESub) iter.next();
//      System.out.println( loadedMsg.getRO() + " = " + loadedMsg.getDE());
//    }
    
//    for (int i = 0; i < 10000; i++)
//      dataLayer.addSub();
    


    //    Transaction tx = session.beginTransaction();
    //    ESub message = new ESub("a cumpara", "kaufen");
    //    session.save(message);
    //    tx.commit();
    //    session.close();

    // Second unit of work
    //    Session newSession = HibernateUtil.getSessionFactory().openSession();
    //    Transaction newTransaction = newSession.beginTransaction();
    //    List messages = newSession.createQuery("from ESub m order by m.RO asc").list();
    //    System.out.println( messages.size() + " message(s) found:" );
    //    for ( Iterator iter = messages.iterator(); iter.hasNext(); ){
    //      ESub loadedMsg = (ESub) iter.next();
    //      System.out.println( loadedMsg.getRO() + " = " + loadedMsg.getDE());
    //    }
    //    newTransaction.commit();
    //    newSession.close();
    //    // Shutting down the application
    //    HibernateUtil.shutdown();
  }

}
